﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace HenrryTools.Common
{
    /// <summary>
    /// 工具类1
    /// </summary>
   public class HenrryHelper
    {
        /// <summary>
        /// //自定义带回调的多线程调用方法
        /// </summary>
        /// <param name="threadStart"></param>
        /// <param name="actionCallback"></param>
        public static void ThreadWithCallBack(ThreadStart threadStart)  
        {
            ThreadStart threadstart2 = () =>      //Invoke()方法表示的是委托同步调用
            {
                threadStart.Invoke();         //先调用
                //actionCallback.Invoke();      //后调用，如此便可以保证回调委托必定在多线程委托后执行
            };
            Thread newthread = new Thread(threadstart2);  //开启新线程，执行threadstart2中的方法。
            newthread.Start();                    //线程开始
        }


        /// <summary>
        /// Base64加密
        /// </summary>
        /// <param name="encodeType">加密采用的编码方式</param>
        /// <param name="source">待加密的明文</param>
        /// <returns></returns>
        public static string Base64Encode(Encoding encodeType, string source)
        {
            string encode = string.Empty;
            byte[] bytes = encodeType.GetBytes(source);
            try
            {
                encode = Convert.ToBase64String(bytes);
            }
            catch
            {
                encode = source;
            }
            return encode;
        }
    }
}
